package com.woniuxy.three.pms.filter;

import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.apache.shiro.web.util.WebUtils;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @ProjectName: Pms
 * @Package: com.woniuxy.three.pms.filter
 * @ClassName: UserFormAuthenticationFilter
 * @Author: 12092
 * @Description: 扩展FormAuthenticationFilter实现动态改变LoginUrl
 * @Date: 2019/6/29 15:43
 * @Version: 1.0
 */
public class UserFormAuthenticationFilter extends FormAuthenticationFilter {

    @Override
    protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {

        HttpServletRequest req = (HttpServletRequest) request;
        String loginUrl = getLoginUrl();
        String url = req.getRequestURI();
        if (url.contains("/user/login")) {
            loginUrl = "/front/html/login.html";
        }else if (url.contains("/admin/login")){
            loginUrl = "/hotel/html/login.html";
        }
        WebUtils.issueRedirect(request, response, loginUrl);
    }
}
